package com.miyake.dsp.osa.lab.wrapper;

import org.apache.commons.lang.ArrayUtils;

import com.miyake.dsp.common.CommonTool;
import com.miyake.dsp.common.EdgeDetector;
import com.miyake.dsp.common.EdgeDetectorSetting;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
@LabUiAnnotation(caption="Edge Detector")
public class EdgeDetectorWrapper extends Calculator {
	public static final String INPUTX = "In-X";
	public static final String INPUTY = "In-Y";
	public static final String THRESHOLD = "Diff Thresholds";
	public static final String OUTPUTX = "Out-X";
	public static final String OUTPUTY = "Out-Y";
	public static final String OUTPUTDIFF = "Diff";
	private EdgeDetectorSetting setting;
	
	public EdgeDetectorWrapper(EdgeDetectorSetting setting) {
		this.setting = setting;
		initInput(INPUTX);
		initInput(INPUTY);
		initOutput(THRESHOLD);
		initOutput(OUTPUTX);
		initOutput(OUTPUTY);
		initOutput(OUTPUTDIFF);
	}
	
	@Override
	public synchronized void process() {
		double[] x = null;
		if (getInput(INPUTX) == null) {
			x = CommonTool.fillNumber(getInput(INPUTY).getRealPart().length);
		}
		else {
			x = this.getInput(INPUTX).getRealPart();
		}
		EdgeDetector edge = new EdgeDetector(
				EdgeDetector.Edge.Rise,
				x,
				getInput(INPUTY).getRealPart());
		//rise.setThresholdY(getInput(THRESHOLD).getRealPart()[0]);
		edge.process();
		setOutput(OUTPUTX, edge.getX());
		setOutput(OUTPUTY, edge.getY());
		setOutput(OUTPUTDIFF, edge.getDiff());
		setOutput(THRESHOLD, ArrayUtils.toPrimitive(edge.getThresholds().toArray(new Double[0])) );
	}

	@Override
	public Object getSetting() {
		return null;
	}

}
